home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Games / WHDLoad / Include / whdmacros.i < prev   
Encoding:
Text File  |  2001-03-18  |  7.5 KB  |  339 lines

  1. ;*---------------------------------------------------------------------------
  2. ;  :Module.    whdmacros.i
  3. ;  :Contens.    useful macros for WHDLoad-Slaves
  4. ;  :Author.    Bert Jahn
  5. ;  :EMail.    wepl@whdload.org
  6. ;  :Address.    Franz-Liszt-Straße 16, Rudolstadt, 07404, Germany
  7. ;  :Version.    $Id: whdmacros.i 14.0 2001/03/18 12:34:51 jah Exp jah $
  8. ;  :History.    11.04.99 separated from whdload.i
  9. ;        07.09.00 macro 'skip' fixed for distance of 2
  10. ;        21.09.00 macro 'blitz' small fix
  11. ;  :Copyright.    © 1996-2001 Bert Jahn, All Rights Reserved
  12. ;  :Language.    68000 Assembler
  13. ;  :Translator.    Barfly V2.9
  14. ;---------------------------------------------------------------------------*
  15.  
  16.  IFND WHDMACROS_I
  17. WHDMACROS_I=1
  18.  
  19.     IFND    HARDWARE_CIA_I
  20.     INCLUDE    hardware/cia.i
  21.     ENDC
  22.     IFND    HARDWARE_CUSTOM_I
  23.     INCLUDE    hardware/custom.i
  24.     ENDC
  25.     IFND    HARDWARE_INTBITS_I
  26.     INCLUDE    hardware/intbits.i
  27.     ENDC
  28.     IFND    HARDWARE_DMABITS_I
  29.     INCLUDE    hardware/dmabits.i
  30.     ENDC
  31.  
  32. ;=============================================================================
  33.  
  34.  BITDEF POTGO,OUTRY,15
  35.  BITDEF POTGO,DATRY,14
  36.  BITDEF POTGO,OUTRX,13
  37.  BITDEF POTGO,DATRX,12
  38.  BITDEF POTGO,OUTLY,11
  39.  BITDEF POTGO,DATLY,10
  40.  BITDEF POTGO,OUTLX,9
  41.  BITDEF POTGO,DATLX,8
  42.  BITDEF POTGO,START,0
  43.  
  44. _ciaa        = $bfe001
  45. _ciab        = $bfd000
  46. _custom        = $dff000
  47.  
  48. ****************************************************************
  49. ***** write opcode ILLEGAL to specified address
  50. ill    MACRO
  51.     IFNE    NARG-1
  52.         FAIL    arguments "ill"
  53.     ENDC
  54.         move.w    #$4afc,\1
  55.     ENDM
  56.  
  57. ****************************************************************
  58. ***** write opcode RTS to specified address
  59. ret    MACRO
  60.     IFNE    NARG-1
  61.         FAIL    arguments "ret"
  62.     ENDC
  63.         move.w    #$4e75,\1
  64.     ENDM
  65.  
  66. ****************************************************************
  67. ***** skip \1 instruction bytes on address \2
  68. skip    MACRO
  69.     IFNE    NARG-2
  70.         FAIL    arguments "skip"
  71.     ENDC
  72.     IFNE \1&1
  73.         FAIL    arguments "skip"
  74.     ENDC
  75.     IFEQ \1-2
  76.         move.w    #$4e71,\2
  77.     ELSE
  78.     IFLE \1-126
  79.         move.w    #$6000+\1-2,\2
  80.     ELSE
  81.     IFLE \1-32766
  82.         move.l    #$60000000+\1-2,\2
  83.     ELSE
  84.         FAIL    "skip: distance to large"
  85.     ENDC
  86.     ENDC
  87.     ENDC
  88.     ENDM
  89.  
  90. ****************************************************************
  91. ***** write \1 times opcode NOP starting at address \2
  92. ***** (better to use "skip" instead)
  93. nops    MACRO
  94.     IFNE    NARG-2
  95.         FAIL    arguments "nops"
  96.     ENDC
  97.         movem.l    d0/a0,-(a7)
  98.         IFGT \1-127
  99.             move.w    #\1-1,d0
  100.         ELSE
  101.             moveq    #\1-1,d0
  102.         ENDC
  103.         lea    \2,a0
  104. .lp\@        move.w    #$4e71,(a0)+
  105.         dbf    d0,.lp\@
  106.         movem.l    (a7)+,d0/a0
  107.     ENDM
  108.  
  109. ****************************************************************
  110. ***** write opcode JMP \2 to address \1
  111. patch    MACRO
  112.     IFNE    NARG-2
  113.         FAIL    arguments "patch"
  114.     ENDC
  115.         move.w    #$4ef9,\1
  116.         pea    (\2,pc)
  117.         move.l    (a7)+,2+\1
  118.     ENDM
  119.  
  120. ****************************************************************
  121. ***** write opcode JSR \2 to address \1
  122. patchs    MACRO
  123.     IFNE    NARG-2
  124.         FAIL    arguments "patchs"
  125.     ENDC
  126.         move.w    #$4eb9,\1
  127.         pea    (\2,pc)
  128.         move.l    (a7)+,2+\1
  129.     ENDM
  130.  
  131. ****************************************************************
  132. ***** wait that blitter has finished his job
  133. ***** (this is adapted from graphics.WaitBlit, see autodocs for
  134. *****  hardware bugs and caveats)
  135. ***** if \1 is given it must be an address register containing _custom
  136. BLITWAIT MACRO
  137.     IFEQ    NARG-1
  138.         tst.b    (dmaconr,\1)
  139. .waitb\@    tst.b    (_ciaa)        ;this avoids blitter slow down
  140.         tst.b    (_ciaa)
  141.         btst    #DMAB_BLTDONE-8,(dmaconr,\1)
  142.         bne.b    .waitb\@
  143.         tst.b    (dmaconr,\1)
  144.     ELSE
  145.         tst.b    (_custom+dmaconr)
  146. .waitb\@    tst.b    (_ciaa)        ;this avoids blitter slow down
  147.         tst.b    (_ciaa)
  148.         btst    #DMAB_BLTDONE-8,(_custom+dmaconr)
  149.         bne.b    .waitb\@
  150.         tst.b    (_custom+dmaconr)
  151.     ENDC
  152.     ENDM
  153.  
  154. ****************************************************************
  155. ***** wait of vertical blank
  156. ***** if \1 is given it must be an address register containing _custom
  157. waitvb    MACRO
  158.     IFEQ    NARG-1
  159. .1\@        btst    #0,(vposr+1,\1)
  160.         beq    .1\@
  161. .2\@        btst    #0,(vposr+1,\1)
  162.         bne    .2\@
  163.     ELSE
  164. .1\@        btst    #0,(_custom+vposr+1)
  165.         beq    .1\@
  166. .2\@        btst    #0,(_custom+vposr+1)
  167.         bne    .2\@
  168.     ENDC
  169.     ENDM
  170.  
  171. ****************************************************************
  172. ***** wait for pressing any button
  173. ***** if \1 is given it must be an address register containing _custom
  174. waitbutton    MACRO
  175.     IFEQ    NARG
  176.         move.l    a0,-(a7)
  177.         lea    (_custom),a0
  178. .down\@        bsr    .wait\@
  179.         btst    #CIAB_GAMEPORT0,(ciapra+_ciaa)        ;LMB
  180.         beq    .up\@
  181.         btst    #POTGOB_DATLY-8,(potinp,a0)        ;RMB
  182.         beq    .up\@
  183.         btst    #CIAB_GAMEPORT1,(ciapra+_ciaa)        ;FIRE
  184.         bne    .down\@
  185. .up\@        bsr    .wait\@                    ;entprellen
  186.         btst    #CIAB_GAMEPORT0,(ciapra+_ciaa)        ;LMB
  187.         beq    .up\@
  188.         btst    #POTGOB_DATLY-8,(potinp,a0)        ;RMB
  189.         beq    .up\@
  190.         btst    #CIAB_GAMEPORT1,(ciapra+_ciaa)        ;FIRE
  191.         beq    .up\@
  192.         bsr    .wait\@                    ;entprellen
  193.         bra    .done\@
  194. .wait\@        waitvb    a0
  195.         rts
  196. .done\@        move.l    (a7)+,a0
  197.     ELSE
  198.     IFEQ    NARG-1
  199. .down\@        bsr    .wait\@
  200.         btst    #CIAB_GAMEPORT0,(ciapra+_ciaa)        ;LMB
  201.         beq    .up\@
  202.         btst    #POTGOB_DATLY-8,(potinp,\1)        ;RMB
  203.         beq    .up\@
  204.         btst    #CIAB_GAMEPORT1,(ciapra+_ciaa)        ;FIRE
  205.         bne    .down\@
  206. .up\@        bsr    .wait\@                    ;entprellen
  207.         btst    #CIAB_GAMEPORT0,(ciapra+_ciaa)        ;LMB
  208.         beq    .up\@
  209.         btst    #POTGOB_DATLY-8,(potinp,\1)        ;RMB
  210.         beq    .up\@
  211.         btst    #CIAB_GAMEPORT1,(ciapra+_ciaa)        ;FIRE
  212.         beq    .up\@
  213.         bsr    .wait\@                    ;entprellen
  214.         bra    .done\@
  215. .wait\@        waitvb    \1
  216.         rts
  217. .done\@
  218.     ELSE
  219.         FAIL    arguments "waitbutton"
  220.     ENDC
  221.     ENDC
  222.     ENDM
  223.  
  224. waitbuttonup    MACRO
  225.     IFEQ    NARG
  226.         move.l    a0,-(a7)
  227.         lea    (_custom),a0
  228. .up\@        bsr    .wait\@                    ;entprellen
  229.         btst    #CIAB_GAMEPORT0,(ciapra+_ciaa)        ;LMB
  230.         beq    .up\@
  231.         btst    #POTGOB_DATLY-8,(potinp,a0)        ;RMB
  232.         beq    .up\@
  233.         btst    #CIAB_GAMEPORT1,(ciapra+_ciaa)        ;FIRE
  234.         beq    .up\@
  235.         bsr    .wait\@                    ;entprellen
  236.         bra    .done\@
  237. .wait\@        waitvb    a0
  238.         rts
  239. .done\@        move.l    (a7)+,a0
  240.     ELSE
  241.     IFEQ    NARG-1
  242. .up\@        waitvb    \1                    ;entprellen
  243.         btst    #CIAB_GAMEPORT0,(ciapra+_ciaa)        ;LMB
  244.         beq    .up\@
  245.         btst    #POTGOB_DATLY-8,(potinp,\1)        ;RMB
  246.         beq    .up\@
  247.         btst    #CIAB_GAMEPORT1,(ciapra+_ciaa)        ;FIRE
  248.         beq    .up\@
  249.         waitvb    \1                    ;entprellen
  250.     ELSE
  251.         FAIL    arguments "waitbuttonup"
  252.     ENDC
  253.     ENDC
  254.     ENDM
  255.  
  256. ****************************************************************
  257. ***** flash the screen and wait for LMB
  258. blitz        MACRO
  259.     ;    move    #DMAF_SETCLR!DMAF_RASTER,dmacon+_custom
  260.         move.l    d0,-(a7)
  261. .lpbl\@        move    #$4200,bplcon0+_custom
  262.         move.w    d0,$dff180
  263.         subq.w    #1,d0
  264.         btst    #6,$bfe001
  265.         bne    .lpbl\@
  266.         waitvb                    ;entprellen
  267.         waitvb                    ;entprellen
  268. .lp2bl\@    move    #$4200,bplcon0+_custom
  269.         move.w    d0,$dff180
  270.         subq.w    #1,d0
  271.         btst    #6,$bfe001
  272.         beq    .lp2bl\@
  273.         waitvb                    ;entprellen
  274.         waitvb                    ;entprellen
  275.         clr.w    color+_custom
  276.         move.l    (a7)+,d0
  277.         ENDM
  278.  
  279. ****************************************************************
  280. ***** color the screen and wait for LMB
  281. bwait        MACRO
  282.         move    #$1200,bplcon0+_custom
  283. .wd\@
  284.     IFEQ NARG
  285.         move.w    #$ff0,color+_custom        ;yellow
  286.     ELSE
  287.         move.w    #\1,color+_custom
  288.     ENDC
  289.         btst    #6,$bfe001
  290.         bne    .wd\@
  291.         waitvb                    ;entprellen
  292.         waitvb                    ;entprellen
  293. .wu\@        btst    #6,$bfe001
  294.         beq    .wu\@
  295.         waitvb                    ;entprellen
  296.         waitvb                    ;entprellen
  297.         clr.w    color+_custom
  298.         ENDM
  299.  
  300. ****************************************************************
  301. ***** install Vertical-Blank-Interrupt which quits on LMB pressed
  302. QUITVBI        MACRO
  303.         move.l    a0,-(a7)
  304.         lea    (.vbi,pc),a0
  305.         move.l    a0,$6c
  306.         bra    .g
  307. .vbi        btst    #6,$bfe001
  308.         beq    .vbi+1        ;create "address error"
  309.         move.w    #INTF_VERTB,_custom+intreq
  310.         rte
  311. .g        move.w    #INTF_SETCLR!INTF_INTEN!INTF_VERTB,_custom+intena
  312.         move.w    #INTF_VERTB,_custom+intreq
  313.         move.l    (a7)+,a0
  314.     ENDM
  315.  
  316. ****************************************************************
  317. ***** set all registers to zero
  318. resetregs    MACRO
  319.         moveq    #0,d0
  320.         moveq    #0,d1
  321.         moveq    #0,d2
  322.         moveq    #0,d3
  323.         moveq    #0,d4
  324.         moveq    #0,d5
  325.         moveq    #0,d6
  326.         moveq    #0,d7
  327.         sub.l    a0,a0
  328.         sub.l    a1,a1
  329.         sub.l    a2,a2
  330.         sub.l    a3,a3
  331.         sub.l    a4,a4
  332.         sub.l    a5,a5
  333.         sub.l    a6,a6
  334.     ENDM
  335.  
  336. ;=============================================================================
  337.  
  338.  ENDC
  339.